<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Member_Model extends CI_Model{
    
    const TABLE_MEMBERS = 'app_sys_member';
	
    function __construct(){
        parent::__construct();    
    }
	
    public function getAll(){
        $query=$this->db->get(self::TABLE_MEMBERS);
        return $query->row();
    }
	
	// get for username or id
    public function getMember($key){
		
        	if(is_numeric($key)){
				$this->db->where(array('memberId'=>$key));
			}else{
				$this->db->where(array('username'=>$key));
			}
						
        	$query=$this->db->get_where(self::TABLE_MEMBERS,array('del_flag'=>0));
        	return $query->row();
    }
    
    //get for email
    public function getMemberByEmail($key){
        
        $query=$this->db->get_where(self::TABLE_MEMBERS,array('email'=>$key));
        //debug($query->row());
        //die();
        return $query->row();
        
        
    }
    // flexi grid function 
    function get_members(){
        
        $this->db->select("memberId,username,firstName,lastName,departmentId,email")
                    ->from(self::TABLE_MEMBERS);
        $this->flexigrid->build_query();
        $return['records']=$this->db->get();
        
        $this->db->select('count(memberId) as record_count')->from(self::TABLE_MEMBERS);
        $this->flexigrid->build_query(FALSE);
        $record_count=$this->db->get();
        $row=$record_count->row();
        $return['record_count']=$row->record_count;
        
        return $return;
    }
    public function insertMember($obj){
        //debug($obj);
        return $this->db->insert(self::TABLE_MEMBERS,$obj);
    }
   
}